package com.sky.common.track;

import java.util.Date;
import java.util.Iterator;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

/**
 * 警报数据管家
 *
 *
 */
public class AlarmManager {

    /**
     * 警报信息
     */
    private static final Map<String, AlarmInfo> alarmMap = new ConcurrentHashMap<>();


    /**
     * 增加一条警报
     *
     * @param taskId   任务id
     * @param deviceId 设备id
     * @param className 类别
     * @param auto 是否自主跟踪
     */
    public static void add(String taskId, String deviceId,String className,boolean auto) {
        Date now = new Date();
        AlarmInfo alarmInfo = new AlarmInfo(taskId, deviceId, className,auto, now, now);
        String key = deviceId + "_" + taskId;
        alarmInfo = alarmMap.putIfAbsent(key, alarmInfo);
        if (alarmInfo != null) {
            alarmInfo.setEndTime(now);
        }
    }


    /**
     * 获取警报信息迭代器
     *
     * @return 迭代器
     */
    public static Iterator<Map.Entry<String, AlarmInfo>> iterator() {
        return alarmMap.entrySet().iterator();
    }


}
